package njust.edu.web;

import njust.edu.dao.TradeDao;
import njust.edu.dao.impl.TradeDaoImpl;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class UserSalary {
    private Long id;
    private String name;
    private Double monthGet;
    private Double dayGet;

    @Override
    public String toString() {
        return "UserSalary{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", monthGet=" + monthGet +
                ", dayGet=" + dayGet +
                '}';
    }

    public Double getDayGet() {
        return dayGet;
    }

    public void setDayGet(Double dayGet) {
        this.dayGet = dayGet;
    }



    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Double getMonthGet() {
        return monthGet;
    }
    public void setMonthGet(Double monthGet) {
        this.monthGet = monthGet;
    }

    public  Double staff_getmonthget(Long staff_id,String Datefrom){
        TradeDao tradeDao=new TradeDaoImpl();

        // TODO: 2021/9/28 把java.util.Date转化为java.sql.Date 
        String yearStr = Datefrom.substring(0,4);
        String monStr = Datefrom.substring(5,7);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
        java.util.Date d = null;
        try {
            d = format.parse(Datefrom);
        } catch (Exception e) {
            e.printStackTrace();
        }
        java.sql.Date datefrom = new java.sql.Date(d.getTime());
        // TODO: 2021/9/28 到这里   
        
        int year= Integer.parseInt(yearStr);
        int month = Integer.parseInt(monStr);

//        System.out.println(year);
//        System.out.println(month);

        Calendar ca = Calendar.getInstance();

        ca.set(Calendar.YEAR, year);

        ca.set(Calendar.MONTH, month-1);

        ca.set(Calendar.DAY_OF_MONTH, 31);

        java.util.Date date = ca.getTime();

//        System.out.println(date);

        setId(staff_id);
//        System.out.println(new Date(date.getTime()));

        monthGet=tradeDao.getUserMonthSalary(id,
                datefrom, new Date(date.getTime()));

//        System.out.println(monthGet);

        return  monthGet;
    }

}
